package kmp;

/**
 * @program: data_structures_algorithms
 * @description: 字符串暴力匹配BF
 * @author: lld
 * @create: 2020-11-17 19:31
 **/
public class ViolentMatch {
    public static void main(String[] args) {
        String s1="ab badabdabcc";
        String s2="abc";
        char[] c1=s1.toCharArray();
        char[] c2=s2.toCharArray();
        int i=0;
        int j=0;
        while (i<c1.length&&j<c2.length){
            if(c1[i]==c2[j]){
                i++;
                j++;
            }else {
                i=i-j+1;
                j=0;
            }
        }
            if(j==c2.length){
                System.out.println("匹配到了，从"+(i-j)+"到"+i+":"+s1.substring((i-j), i));
            }else {
                System.out.println("没有匹配到");
            }

    }
}
